<?php
// +----------------------------------------------------------------------
// | Author: wyd 2025/10/19
// | DESC: 
// +----------------------------------------------------------------------

declare (strict_types=1);

use My\core\annotations\DbAnnotation;
use My\core\frame\DbManager;
use  \My\core\BeanFactory;

return [
    //属性注解
    DbAnnotation::class=>function (\ReflectionProperty $prop, object $instance, array $args) {

        $className = DbManager::class .'_' .$args['connect'];
        //这里是个单例模式,因为带了下划线，第一次肯定取不到
        $manager = BeanFactory::getBean($className);
        if(!$manager){
            $baseManager = BeanFactory::getBean(DbManager::class);
            $manager = clone $baseManager;
            BeanFactory::setBean($className,$manager);
        }

        //外部改变私有属性
        $manager->setCurrentConnection($args['connect']);


        $prop->setAccessible(true);   //可以设置私有属性；
        $prop->setValue($instance, $manager);     //把数据库实例化对象赋值给类的属性
    }
];